class HAudio {
	_audio = null;
	soucrePath = '';
	src = "";
	constructor(soucrePath, src = '') {
		this.src = src || ''
		this.soucrePath = soucrePath
	};
	getSrc() {
		if (!this.src) {
			this.src = uni.getStorageSync('imgUrl')
		}
	}
	packageSrc() {
		this.getSrc()
		return `${this.src}${this.soucrePath}`
	}
	play(soucrePath = '') {
		let ctx = uni.createInnerAudioContext()
		this._audio = ctx
		ctx.src = this.packageSrc() || soucrePath
		ctx.autoplay = false
		ctx.play()
		let duration = 999999
		 ctx.onCanplay(()=>{
			 wx.showToast({
			 	title: '录音播放中',
			 	mask: true,
			 	duration: duration,
			 	icon: 'loading',
			 	complete: () => {
			 		console.log('complete')
			 	}
			 })
		 })
		ctx.onError(({errCode}) => {
			const errCodeText = {
				'10001': '系统错误',
				'10002': '网络错误',
				'10003': '文件错误',
				'10004': '文件格式错误',
				'-1': '未知错误'
			} 
			wx.showToast({
				title: `${errCodeText[errCode]}`,
				icon: 'error'
			})
		})
		ctx.onEnded(() => {
			wx.hideToast()
		})
	}
}

export default HAudio
